package com.gdth.bank.activity.setting;

import java.util.Date;
import java.util.Random;

import com.gdth.bank.BankApplication;
import com.gdth.bank.R;
import com.gdth.bank.StringParam;
import com.gdth.bank.bean.SyjybBean;
import com.gdth.bank.presenter.SyJybPresenter;
import com.gdth.bank.view.SyJyBView;
import com.gdth.core.annotation.view.ViewInject;
import com.gdth.core.widget.BaseActivity;
import com.gdth.database.bean.TAppYh;
import com.gdth.utils.CodeUtils;
import com.gdth.utils.GsonUtil;
import com.gdth.widget.dialog.BaseToast;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class InformationActivity extends BaseActivity  implements SyJyBView{
	
	@ViewInject(id=R.id.header_label_title) TextView txt_header_title;
	@ViewInject(id=R.id.header_btn_left, click="finishClick") TextView txt_header_left;
    @ViewInject(id=R.id.imformation_btn_commit,click="commitClick") Button txt_commit;
    @ViewInject(id=R.id.imformation_btn_reset,click="resetClick") Button txt_reset;
    @ViewInject(id=R.id.header_btn_right)  EditText txt_imformation;
	@ViewInject(id=R.id.input_verification)  EditText input_verification;
	@ViewInject(id=R.id.img)
	ImageView img;
    SyJybPresenter mSyJybPresenter;
    SyjybBean  mSyjybBean;
    /** 提示框 */
    ProgressDialog mProgressDialog;
    public String verification = "";
    
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.acitvity_setting_imformation);
		initView();
	}
	
	private void initView(){
		txt_header_title.setText(R.string.param16);
		txt_imformation = (EditText) findViewById(R.id.imformation_txt_imformation);
		mSyJybPresenter = new SyJybPresenter(this);
		mSyjybBean = new SyjybBean();
		mProgressDialog=new ProgressDialog(this);
		createCodeClick();
		img.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				createCodeClick();
			}
		});
	}
	
	public void commitClick(View arg0) {
		String val = txt_imformation.getText().toString();
		if(null == val || val.isEmpty()){
			Toast.makeText(InformationActivity.this,"使用建议不能为空", Toast.LENGTH_SHORT).show();
			return;
		}

		String inputCode = input_verification.getText().toString();
		if(null == inputCode || inputCode.isEmpty()){
			Toast.makeText(InformationActivity.this,"请输入验证码", Toast.LENGTH_SHORT).show();
			return;
		}

		if(!inputCode.equals(verification)){
			Toast.makeText(InformationActivity.this,"验证码输入错误", Toast.LENGTH_SHORT).show();
			return;
		}

		TAppYh user = BankApplication.mInstance.getCurrentUser();
		mSyjybBean.setCjsj(new Date());
		mSyjybBean.setTjrsfz(user.getZh());
		mSyjybBean.setTjr(user.getXm());
		mSyjybBean.setSyjy(val);
		String str = GsonUtil.getGson().toJson(mSyjybBean);
		if(val!=null){
			mSyJybPresenter.saveTjSyJyb(str);
		}

		/*BaseToast.getInstance().ShowSystemToast(this, val);*/
	}
	public void resetClick(View arg0){
		txt_imformation.setText("");
	}

	@Override
	public void showProgressDialog(String msg) {
		// TODO Auto-generated method stub
		mProgressDialog.setMessage(msg);
		mProgressDialog.show();
	}

	@Override
	public void hideProgressDialog() {
		// TODO Auto-generated method stub
		mProgressDialog.hide();
		
	}

	@Override
	public void showMessage(String msg) {
		// TODO Auto-generated method stub
		BaseToast.getInstance().ShowSystemToast(this, msg);
		createCodeClick();
		input_verification.setText("");
	}

	@Override
	public void tjSyJyB(String str) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void success() {
		// TODO Auto-generated method stub
		txt_imformation.setText("");
	}

	public void  createCodeClick(){
		img.setImageBitmap(CodeUtils.getInstance().createBitmap());
		verification = CodeUtils.getInstance().getCode();
	}
  
	
}
